package com.jinxin.platform.cdsideparkmgr.service.impl;

import com.jinxin.platform.base.common.pojo.JsonResult;
import com.jinxin.platform.cdsideparkmgr.bean.CdyardmgrCarInside;
import com.jinxin.platform.cdsideparkmgr.mapper.CdsideparkmgrCarInsideMapper;
import com.jinxin.platform.cdsideparkmgr.service.ICdsideparkmageCarInsideService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.time.LocalDateTime;
import java.util.HashMap;

/**
 * @Author 那个男人
 * @Date 2022/9/27 9:44
 * @Version 1.0
 */
@Service
public class CdsideparkmageCarInsideServiceImpl implements ICdsideparkmageCarInsideService {
    @Autowired
    private CdsideparkmgrCarInsideMapper carInsideMapper;

    @Override
    public JsonResult saveOrUpdate(CdyardmgrCarInside record,boolean isAdd) {
        if (record == null){
            return JsonResult.error("参数错误，操作失败");
        }
        int count;
        String msg = "";
        if(isAdd){
            record.setEnterTime(LocalDateTime.now());
            count = carInsideMapper.insert(record);
            msg = "新增成功";
        }else {
            count = carInsideMapper.updateByKey(record);
            msg = "更新成功";
        }
        if(count > 0){
            return JsonResult.ok(msg,"");
        }else {
            return JsonResult.error("操作失败，请重试");
        }
    }

    @Override
    public CdyardmgrCarInside selectOne(HashMap param) {
        return carInsideMapper.selectOne(param);
    }

    @Override
    public int updateByKey(CdyardmgrCarInside carInside) {
        return carInsideMapper.updateByKey(carInside);
    }
}
